<?php
// +----------------------------------------------------------------------------
// | Tke团队版权所属 [三十年河东三十年河西,莫欺少年穷.!]
// +----------------------------------------------------------------------------
// | Copyright (c) 2014 http://www.itdaodan.com All rights reserved.
// +----------------------------------------------------------------------------
// | Author: PHP@妖孽 <dino_ma@163.com>
// +----------------------------------------------------------------------------
/**
 +------------------------------------------------------------------------------
 * 客服系统->基础数据维护
 +------------------------------------------------------------------------------
 * @version   1.0
 * @since 2014-8-28
 +------------------------------------------------------------------------------
 */
namespace Admin\Controller;

class BaseController extends AdminController {

	/**
	 *@todo 需求维护管理
	 *@author fzh<fanzhaohai@hrbjjhh.com>
	 */
	public function index(){
	    $this->assign('meta_title','需求维护');
	    $this->assign('_list',$this->lists('service_demand'));
	    $this->display();
	}

	/**
	 *@todo 添加需求维护
	 *@author fzh<fanzhaohai@hrbjjhh.com>
	 */
	public function addDemand(){
	    if(IS_POST){
	        $obj=D('ServiceDemand');
	        $id=$obj->update();
	        if(false === $id){
	            $this->error($obj->getError());
	        }else{
	            S('service_all_demand',null);
	            action_log('demand_add', 'ServiceDemand', $id, UID);
	            $this->success('新增成功', U('index'));
	        }
	    } else {
	        $this->assign('info',null);
	        $this->assign('meta_title','新增需求');
	        $this->display('editDemand');
	    }
	}

	/**
	 * @todo 修改需求维护
	 * @author fzh<fanzhaohai@hrbjjhh.com>
	 */
	public function editDemand(){
	    if(IS_POST){
	        $obj=D('ServiceDemand');
	        if(false === $obj->update()){
	            $this->error($obj->getError());
	        } else {
	            S('service_all_demand',null);
	            $demand_id = (int)$_POST[$obj->getPk()];
	            if($demand_id>0){
	               action_log('demand_update', 'ServiceDemand', $demand_id, UID);
	            }
	            $this->success('修改成功！', U('index'));
	        }
	    } else {
	        $id=(int)I('get.id');
	        if($id==0){
                $this->error('参数传递错误');
	        }
	        $info=M('service_demand')->field('demand_id,demand_name')->where("demand_id='$id'")->find();
	        $this->assign('info',$info);
	        $this->assign('meta_title','编辑需求');
	        $this->display('editDemand');
	    }
	}


	/**
	 *@todo 需求内容维护管理
	 *@author fzh<fanzhaohai@hrbjjhh.com>
	 */
	public function demandContent(){
	    $id=(int)I('get.pid');
	    if($id ==0){
	        $this->error('参数错误');
	    }
        $this->assign('meta_title','需求内容');
	    $list = $this->lists('service_demand_content', array('demand_id'=>$id,'status'=>1));
	    $this->assign('_list',$list);
	    $this->display('demandContent');
	}

	/**
	 *@todo 添加需求内容维护
	 *@author fzh<fanzhaohai@hrbjjhh.com>
	 */
	public function addDemandContent(){
	    if(IS_POST){
	        $demand_id=(int)I('post.demand_id');
	        if($demand_id ==0){
	            $this->error('参数错误');
	        }
	        $obj = D('ServiceDemandContent');
	        $id=$obj->update();
	        if(false === $id){
	            $this->error($obj->getError());
	        } else {
	            S('service_all_demand',null);
	            action_log('demandContent_add', 'ServiceDemand', $id, UID);
	            $this->success('新增成功！',U('Base/demandContent',array('pid'=>$demand_id)));
	        }
	    } else {
	        $pid=(int)I('get.pid');
	        if($pid ==0){
	            $this->error('参数错误');
	        }
	        $info=M('service_demand')->field('demand_id,demand_name')->where(array('demand_id'=>$pid))->find();
	        $this->assign('meta_title','新增需求内容');
	        $this->assign('info',$info);
	        $this->display('editDemandContent');
	    }
	}

	/**
	 * @todo 修改需求内容维护
	 * @author fzh<fanzhaohai@hrbjjhh.com>
	 */
	public function editDemandContent(){
	    if(IS_POST){
	        $demand_id=(int)I('post.demand_id');
	        if($demand_id ==0){
	            $this->error('参数错误');
	        }
	        $obj=D('ServiceDemandContent');
	        if(false === $obj->update()){
	            $this->error($obj->getError());
	        } else {
	            S('service_all_demand',null);
	            $demand_content_id = (int)$_POST[$obj->getPk()];
	            if($demand_content_id>0){
	                action_log('demandContent_update', 'ServiceDemand', $demand_content_id, UID);
	            }
	            $this->success('修改成功！',U('Base/demandContent',array('pid'=>$demand_id)));
	        }
	    } else {
	        $id=(int)I('get.id');
	        if($id ==0){
	            $this->error('参数错误');
	        }
	        $info=M('service_demand_content')->field('demand_content_id,demand_content_name,demand_id')->where(array('demand_content_id'=>$id))->find();
	        if(!empty($info)){
    	        $service_demand=M('service_demand')->field('demand_name')->where(array('demand_id'=>$info['demand_id']))->find();
                $info['demand_name']=!empty($service_demand)?$service_demand['demand_name']:'';
    	    }else{
    	        $this->error('没有信息');
    	    }
	        $this->assign('info', $info);
	        $this->assign('meta_title','编辑需求内容');
	        $this->display('editDemandContent');
	    }
	}

	/**
	 * @todo 删除需求和内容
	 * @author fzh
	 * @since 2-15-9-11
	 */
    public function setDemandStatus(){
        S('service_all_demand',null);
        $ids    =   (array)I('request.ids');
        foreach ($ids as $id){
            action_log('demand_del', 'ServiceDemand', $id, UID);
        }
        $this->setStatus();
    }

	/**
	 *@todo 小区信息管理
	 */
	public function village(){

		$search_text = strip_tags(I('search_text'));//搜索内容
		$map = array();//初始化查询条件
		//查询条件
		if($search_text != '' && $search_text != null){
			$map['village_name'] = array('like', '%'.(string)$search_text.'%');
		}
		//如果接到行政区id，增加行政区筛选条件
		$province_id = (int)I('province_id');
		if($province_id != 0){
			$map['province_id'] = $province_id;
		}
		//如果接到行政区id，增加行政区筛选条件
		$ward_id = (int)I('ward_id');
		if($ward_id != 0){
			$map['ward_id'] = $ward_id;
		}
		//如果接到城市id，增加行政区筛选条件
		$city_id = (int)I('city_id');
		if($city_id != 0){
			$map['city_id'] = $city_id;
		}
		//列表
		$map['status'] = array('gt',-1);
		$list = $this->lists('Village',$map,'village_id desc','village_id,village_name,ward_id,city_id,into_time,province_id');
		
		//前端页面显示了city_id|city_name,province_id|province_name.通过缓存获取
		$this->assign('_list',$list);
		$this->assign('meta_title','小区管理');
		$this->display('village');
	}

	/**
	 * @todo 小区管理
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function addVillage(){
		if(IS_POST){
			$this->updateVillage();
		}else{
			$this->assign('list',null);//功能用一个页时需要给值null
			$this->assign('meta_title','新增小区');
			$this->assign('meta_title_c','小区管理');
			$this->display('villageAdd');
		}
	}

	/**
	 * @todo 编辑小区
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function editVillage(){
		if(IS_POST){
			$this->updateVillage();
		}else{
			//编辑时，小区详细信息
			$village_id = (int)I('village_id');
			if($village_id == 0){
				$this->error('请正确操作');
			}else{
				$info = D('Admin/Village')->VillageShow($village_id,'village_id,village_name,into_time,city_id,ward_id,province_id');
				//显示
				if(!empty($info)){
					//渲染显示
					$this->assign('list',$info);
					$this->assign('meta_title','更新小区');
					$this->assign('meta_title_c','小区管理');
				}
			}
			$this->display('villageAdd');
		}
	}

	/**
	 * @todo 添加/编辑小区(仅供内部调用)
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	private function updateVillage(){
		$village_id = (int)I('village_id');//更新时ID值
		$obj = D('Admin/Village');
		$id = $obj->update();//新增时ID值
		if(empty($id)){
			$this->error($obj->getError());
		}else{
			S('base_village_list',null);//新增或编辑小区时清除缓存
			if($village_id == 0){
				//新增行为操作
				action_log('addVillage', 'village', $id, UID);
			}else{
				//更新行为操作
				action_log('editVillage', 'village', $village_id, UID);
			}
			$this->success('操作成功',U('village'));
		}
	}

	/**
	 * @todo 小区状态修改
	 * @param string $method 标识
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function changeStatusVillage($method = null){
		$id = array_unique((array)I('id',0));
		$id = is_array($id) ? implode(',',$id) : $id;
		if(empty($id)) {
			$this->error('请选择要操作的数据!');
		}
		$map[D('Admin/Village')->getPk()] = array('in',$id);
		switch (strtolower($method) ){
			case 'forbid':
				$this->forbid('Village', $map );
				break;
			case 'resume':
				$this->resume('Village', $map );
				break;
			case 'delete':
				S('base_village_list',null);//新增或编辑小区时清除缓存
				action_log('changeStatusVillage', 'village', $id, UID);
				$this->delete('Village', $map );
				break;
			default:
				$this->error('参数非法');
		}
	}

	/**
	 * @todo 销售网点管理
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function salePoint(){
		$search_text = strip_tags(I('search_text'));//搜索内容
		$map = array();//初始化查询条件
		//查询条件
		if($search_text != '' && $search_text != null){
			$map['sale_point_name'] = array('like', '%'.(string)$search_text.'%');
		}
		//如果接到行政区id，增加行政区筛选条件
		$province_id = (int)I('province_id');
		if($province_id != 0){
			$map['province_id'] = $province_id;
		}
		$ward_id = (int)I('ward_id');
		if($ward_id != 0){
			$map['ward_id'] = $ward_id;
		}
		$city_id = (int)I('city_id');
		if($city_id != 0){
			$map['city_id'] = $city_id;
		}

		//列表
		$map['status'] = array('gt',-1);
		$list = $this->lists('service_sale_point',$map,'sale_point_id desc','sale_point_id,sale_point_name,ward_id,city_id');
		//前端city_id|getCityName获取缓存,函数位置comment/comment/function.php
 		$this->assign('_list',$list);
 		$this->assign('meta_title','销售网点管理');
		$this->display('salePointIndex');
	}

	/**
	 * @todo 新增销售网点
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function add(){
		if(IS_POST){
			$this->updateSalePoint();
		}else{
			$this->assign('list',null);//功能用一个页时需要给值null
			$this->assign('meta_title','新增销售网点');
			$this->assign('meta_title_c','销售网点管理');
			$this->display('salePointAdd');
		}
	}

	/**
	 * @todo 编辑销售网点
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function edit(){
		if(IS_POST){
			$this->updateSalePoint();
		}else{
			//编辑时，销售网点详细信息
			$sale_point_id = (int)I('sale_point_id');
			if($sale_point_id == 0){
				$this->error('请正确操作');
			}
			$info = D('Admin/ServiceSalePoint')->ServiceSalePointShow($sale_point_id,'sale_point_id,sale_point_name,city_id,ward_id,province_id');
			if(!empty($info)){

				//渲染显示
				$this->assign('list',$info);
				$this->assign('meta_title','更新销售网点');
				$this->assign('meta_title_c','销售网点管理');
			}
			$this->display('salePointAdd');
		}
	}

	/**
	 * @todo 添加/编辑销售网点(仅供内部调用)
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	private function updateSalePoint(){
		$sale_point_id = (int)I('sale_point_id');//更新时ID值
		$obj = D('Admin/ServiceSalePoint');
		$id = $obj->update();//新增时ID值
		if(empty($id)){
			$this->error($obj->getError());
		}else{
			S('service_get_area_sale_point_list',null);//新增或编辑销售网点时清除缓存
			if($sale_point_id == 0){
				//新增行为操作
				action_log('addSalePoint', 'service_sale_point', $id, UID);
			}else{
				//更新行为操作
				action_log('editSalePoint', 'service_sale_point', $sale_point_id, UID);
			}
			$this->success('操作成功',U('salePoint'));
		}
	}

	/**
	 * @todo 销售网点状态修改(假删除)
	 * @param string $method 标识
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function changeStatus($method = null){
		$id = array_unique((array)I('id',0));
		$id = is_array($id) ? implode(',',$id) : $id;
		if(empty($id)) {
			$this->error('请选择要操作的数据!');
		}
		$map[D('Admin/ServiceSalePoint')->getPk()] = array('in',$id);
		switch (strtolower($method) ){
			case 'forbid':
				$this->forbid('ServiceSalePoint', $map );
				break;
			case 'resume':
				$this->resume('ServiceSalePoint', $map );
				break;
			case 'delete':
				S('service_get_area_sale_point_list',null);//新增或编辑销售网点时清除缓存
				action_log('changeStatusSalePoint', 'service_sale_point', $id, UID);
				$this->delete('ServiceSalePoint', $map );
				break;
			default:
				$this->error('参数非法');
		}
	}

	/**
	 * @todo 班车点管理
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function busPoint(){

		$search_text = strip_tags(I('search_text'));//搜索内容
		$map = array();//初始化查询条件
		//查询条件
		if($search_text != '' && $search_text != null){
			$map['bus_point_name'] = array('like', '%'.(string)$search_text.'%');
		}
		//如果接到行政区id，增加行政区筛选条件
		$province_id = (int)I('province_id');
		if($province_id != 0){
			$map['province_id'] = $province_id;
		}
		//如果接到行政区id，增加行政区筛选条件
		$ward_id = (int)I('ward_id');
		if($ward_id != 0){
			$map['ward_id'] = $ward_id;
		}
		//如果接到城市id，增加行政区筛选条件
		$city_id = (int)I('city_id');
		if($city_id != 0){
			$map['city_id'] = $city_id;
		}
		//查库
		$map['status'] = array('gt',-1);
		$list = $this->lists('service_bus_point',$map,'bus_point_id desc','bus_point_id,bus_point_name,ward_id,city_id');
		//调取comment/comment/function.php使用函数getWardName前端获取城市,行政区缓存
		$this->assign('_list',$list);
		$this->assign('meta_title','班车点管理');
		$this->display('busPointIndex');
	}

	/**
	 * @todo 班车点
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function addBus(){
		if(IS_POST){
			$this->updateBus();
		}else{
			$this->assign('list',null);//功能用一个页时需要给值null
			$this->assign('meta_title','新增班车点');
			$this->assign('meta_title_c','班车点管理');
			$this->display('busPointAdd');
		}
	}

	/**
	 * @todo 编辑班车点
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function editBus(){
		if(IS_POST){
			$this->updateBus();
		}else{
			//编辑时，班车点详细信息
			$bus_point_id = (int)I('bus_point_id');
			if($bus_point_id == 0){
				$this->error('请正确操作');
			}
			$info = D('Admin/ServiceBusPoint')->ServiceBusPointShow($bus_point_id,'bus_point_id,bus_point_name,bus_point_addres,ward_id,city_id,province_id');
			if(!empty($info)){
				//渲染显示
				$this->assign('list',$info);
				$this->assign('meta_title','更新班车点');
				$this->assign('meta_title_c','班车点管理');
			}
			$this->display('busPointAdd');
		}
	}

	/**
	 * @todo 添加/编辑班车点(仅供内部调用)
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	private function updateBus(){
		$bus_point_id = (int)I('bus_point_id');//更新时ID值
		$obj = D('Admin/ServiceBusPoint');
		$id = $obj->update();
		if(empty($id)){
			$this->error($obj->getError());
		}else{
			S('service_get_area_bus_list',null);//新增或编辑班车点时清除缓存
			if($bus_point_id == 0){
				//新增行为操作
				action_log('addBusPoint', 'service_bus_point', $id, UID);
			}else{
				//更新行为操作
				action_log('editBusPoint', 'service_bus_point', $bus_point_id, UID);
			}
			$this->success('操作成功',U('busPoint'));
		}
	}

	/**
	 * @todo 班车点状态修改
	 * @param string $method 标识
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function changeStatusBus($method = null){
		$id = array_unique((array)I('id',0));
		$id = is_array($id) ? implode(',',$id) : $id;
		if(empty($id)) {
			$this->error('请选择要操作的数据!');
		}
		$map[D('Admin/ServiceBusPoint')->getPk()] = array('in',$id);
		switch (strtolower($method) ){
			case 'forbid':
				$this->forbid('ServiceBusPoint', $map );
				break;
			case 'resume':
				$this->resume('ServiceBusPoint', $map );
				break;
			case 'delete':
				S('service_get_area_bus_list',null);//新增或编辑班车点时清除缓存
				action_log('changeStatusBusPoint', 'service_bus_point', $id, UID);
				$this->delete('ServiceBusPoint', $map );
				break;
			default:
				$this->error('参数非法');
		}
	}

	/**
	 *@todo 短信管理
	 *@author mahuan<mahuan1768@126.com>
	 */
	public function sms(){
	    $sms_template_name = strip_tags(I('sms_template_name'));
	    $map = array();
	    $map['status'] = array('gt',-1);
	    if($sms_template_name!=''){
	        $map['sms_template_name']    =   array('like', '%'.(string)$sms_template_name.'%');
	    }
	    $list = $this->lists('service_sms_template',$map,'sms_template_id','sms_template_id,sms_template_name,sms_template_content,status,create_time,update_time');
        $this->assign('list',$list);
	    $this->assign('meta_title','短信维护');
        $this->display();
	}

	/**
	 * @todo 增加短信模板
	 * @author mahuan<mahuan1768@126.com>
	 */
	
	public function addSms(){
	    if(IS_POST){
    	    $obj=D('ServiceSmsTemplate');
    	    $id=$obj->update();
        	if(false === $id){
        	    $this->error($obj->getError());
        	} else {
        	    S('service_activity_sms_list',null);
        	    action_log('sms_add', 'service_sms_template', $id, UID);
        	    $this->success('新增成功！', U('sms'));
        	}
	    }else{
	        $this->assign('info',NULL);
	        $this->meta_title= '新增短信模板';
	        $this->url=U('Base/addSms');
	        $this->display('editSms');
	    }
	}

	/**
	 * @todo 短信模板编辑
	 * @param int sms_template_id 短信模板主键
	 * @author mahuan<mahuan@hrbjjhh.com>
	 */
	public function editSms(){
	    $id = (int)I('sms_template_id');
	    if(IS_POST){
	        $obj=D('ServiceSmsTemplate');
	        if(false === $obj->update()){
	            $this->error($obj->getError());
	        } else {
	            S('service_activity_sms_list',null);
	            $id = (int)$_POST[$obj->getPk()];
	            action_log('sms_update', 'service_sms_template', $id, UID);
	            $this->success('修改成功！', U('sms'));
	        }
	        
	    }else{
	        if($id==0){
	            $this->error('请不要非法访问~');
	        }
	        $info = M('ServiceSmsTemplate')->where(array('sms_template_id'=>$id))->field('sms_template_id,sms_template_name,sms_template_content')->find();
	        if(empty($info)){
	            $this->error('需要编辑的模板不存在！');
	        }
	        $this->assign('info',$info);
	        $this->meta_title= '编辑短信模板';
	        $this->url=U('Base/editSms');
	        $this->display('editSms');
	    }
	}

	/**
	 *@todo 更新短信模版(仅供内部调用)
	 *@author PHP@妖孽 <mashengjie@hrbjjhh.com>
	 */
	private  function update(){
	    $obj = D('ServiceSmsTemplate');
	    $res =$obj->update();
	    if(!$res){
	        $this->error($obj->getError());
	    }else{
	        $this->success('操作成功', U('Base/sms'));
	    }
	}

	/**
	 * @todo 删除短信
	 * @author fzh
	 * @since 2-15-9-11
	 */
	public function setSmsStatus(){
	   S('service_activity_sms_list',null);
	   $ids    =   (array)I('request.ids');
	   foreach ($ids as $id){
	       action_log('sms_del', 'service_sms_template', $id, UID);
	   }
	   $this->setStatus();
	}

	/**
	 * @todo   区域管理-省份
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function area(){
		$map = array();//初始化查询条件
		$map['status'] = array('gt',-1);
		
		//查询省份
		$list = $this->lists('Province',$map,'Province_id asc','Province_id,Province_name');
		$this->assign('_list',$list);
		$this->assign('meta_title','区域管理');
		$this->display('areaIndex');
	}
	
	/**
	 * @todo   区域管理-城市
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function areaCity(){
		$map = array(); //初始化变量
		$map['status'] = array('gt',-1);
		$province_id = I('get.province_id',0); //index点击接到省份名称id，如果没接到赋值0
		if($province_id != 0){
			$map['province_id'] = $province_id;
		}
		$city = $this->lists('City',$map,'city_id asc','city_name,city_id,province_id');
		$this->assign('_list',$city);
		$this->assign('province',$province_id);
		$this->assign('meta_title','区域管理');
		$this->display('areaCityIndex');
	}
	
	/**
	 * @todo   区域管理-行政区
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function areaWard(){
		$map = array(); //初始化变量
		$map['status'] = array('gt',-1);
		$search_text = strip_tags(I('search_text'));//搜索内容
		if($search_text != '' && $search_text != null){
			$map['ward_name'] = array('like', '%'.(string)$search_text.'%');
		}
		$city_id = I('get.city_id',0); //index点击接到城市名称id，如果没接到赋值0
		if($city_id != 0){
			$map['city_id'] = $city_id;	
			$this->assign('city_id',$city_id);
		} 
		$ward = $this->lists('Ward',$map,'ward_id asc','ward_name,ward_id,province_id,city_id');
		$this->assign('_list',$ward);
		$this->assign('meta_title','区域管理');
		$this->display('areaWardIndex');
	}

	/**
	 * @todo 新增省份
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function addProvince(){
		if(IS_POST){
			$this->updateProvince();
		}else{
			$this->assign('list',null);//功能用一个页时需要给值null
			$this->assign('meta_title','新增省份');
			$this->assign('meta_title_c','区域管理');
			$this->display('provinceAdd');
		}
	}

	/**
	 * @todo 新增城市
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function addCity(){
		if(IS_POST){
			$this->updateCity();
		}else{
			$province_id = I('province_id',0);
			if($province_id == 0){
				$this->error('跳转失败，ID缺失');  //新增城市 时没有接到对应省份的id
			}else{
				$this->assign('province',$province_id);
				$this->assign('list',null);//功能用一个页时需要给值null
				$this->assign('meta_title','新增城市');
				$this->assign('meta_title_c','区域管理');
			}
			$this->display('cityAdd');
		}
	}

	/**
	 * @todo 新增行政区
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function addWard(){
		if(IS_POST){
			$this->updateWard();
		}else{
			$city_id = I('city_id',0);
			if($city_id != 0){
				$map['city_id'] = $city_id;
				$city = M('City')->where($map)->field('province_id,city_id')->find();
				$this->assign('city',$city);
				$this->assign('list',null);//功能用一个页时需要给值null
				$this->assign('meta_title','新增行政区');
				$this->assign('meta_title_c','区域管理');
			}else{
				$this->error('跳转失败，ID缺失');  //新增行政区 时没有接到对应城市的id
			}
			$this->display('wardAdd');
		}
	}

	/**
	 * @todo 添加/编辑省份(仅供内部调用)
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	private function updateProvince(){
		$province_id = (int)I('province_id');//更新时ID值
		$obj = D('Admin/Province');
		$id = $obj->update();
		if($id === false){
			$this->error($obj->getError());
		}else{
			S('base_province_list',null);//新增或编辑省份时清除缓存
			if($province_id == 0){
				//新增行为操作
				action_log('addProvince', 'province', $id, UID);
			}else{
				//更新行为操作
				action_log('editProvince', 'province', $province_id, UID);
			}
			$this->success('操作成功',U('area'));
		}
	}

	/**
	 * @todo 添加/编辑城市(仅供内部调用)
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	private function updateCity(){
		$city_id = (int)I('city_id');//更新时ID值
		$obj = D('Admin/City');
		$id = $obj->update();
		if(empty($id)){
			$this->error($obj->getError());
		}else{
			S('base_city_list',null);//新增或编辑城市时清除缓存
			if($city_id == 0){
				//新增行为操作
				action_log('addCity', 'city', $id, UID);
			}else{
				//更新行为操作
				action_log('editCity', 'city', $city_id, UID);
			}
			$this->success('操作成功',U('area'));
		}
	}


	/**
	 * @todo 添加/编辑行政区(仅供内部调用)
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	private function updateWard(){
		$ward_id = (int)I('ward_id');//更新时ID值
		$obj = D('Admin/Ward');
		$id = $obj->update();
		if(empty($id)){
			$this->error($obj->getError());
		}else{
			S('base_ward_list',null);//新增或编辑行政区时清除缓存
			if($ward_id == 0){
				//新增行为操作
				action_log('addWard', 'ward', $id, UID);
			}else{
				//更新行为操作
				action_log('editWard', 'ward', $ward_id, UID);
			}
			$this->success('操作成功',U('area'));
		}
	}

	/**
	 * @todo 编辑省份
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function editProvince(){
		if(IS_POST){
			$this->updateProvince();
		}else{
			//编辑时，区域详细信息
			$province_id = (int)I('province_id');
			if($province_id == 0){
				$this->error('请正确操作');
			}else{
				$this->assign('list',$province_id);
				$this->assign('meta_title','更新省份');
				$this->assign('meta_title_c','省份管理');
				}
			$this->display('provinceAdd');
			}
		}

	/**
	 * @todo 编辑城市
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function editCity(){
		if(IS_POST){
			$this->updateCity();
		}else{
			//编辑时，区域详细信息
			$city_id = (int)I('city_id');
			if($city_id == 0){
				$this->error('请正确操作');
			}else{
				$info = D('Admin/City')->getCity($city_id,'city_name,city_id,province_id');
				if(!empty($info)){
					$this->assign('list',$info);
					$this->assign('meta_title','更新城市');
					$this->assign('meta_title_c','省份管理');
				}
			}
			$this->display('cityAdd');
		}
	}

	/**
	 * @todo 编辑行政区
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function editWard(){
		if(IS_POST){
			$this->updateWard();
		}else{
			//编辑时，区域详细信息
			$ward_id = (int)I('ward_id');
			if($ward_id == 0){
				$this->error('请正确操作');
			}
			$info = D('Admin/Ward')->getWard($ward_id,'ward_name,ward_id,city_id,province_id');
			if(!empty($info)){
				$this->assign('list',$info);
				$this->assign('meta_title','更新行政区');
				$this->assign('meta_title_c','省份管理');
			}
			$this->display('wardAdd');
		}
	}

	/**
	 * @todo 省份状态修改
	 * @param string $method 标识
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function changeStatusProvince($method = null){
		$id = array_unique((array)I('id',0));
		$id = is_array($id) ? implode(',',$id) : $id;
		if(empty($id)) {
			$this->error('请选择要操作的数据!');
		}
		$map[D('Admin/Province')->getPk()] = array('in',$id);
		switch (strtolower($method) ){
			case 'forbid':
				$this->forbid('Province', $map );
				break;
			case 'resume':
				$this->resume('Province', $map );
				break;
			case 'delete':
				$obj_city = D('Admin/City');
				if(!$obj_city->judgeProvince($id)){
					$this->error($obj_city->getError());
				}else{
					$delete = D('Admin/Province');
					if(!$delete -> deleteProvince($id)){
						$this->error('删除失败!');
					}else{
						S('base_province_list',null);//新增或编辑省份时清除缓存
						action_log('changeStatusProvince', 'province', $id, UID);
						$this->success('删除成功!');
					}
				}
				break;
			default:
				$this->error('参数非法');
		}
	}

	/**
	 * @todo 城市状态修改
	 * @param string $method 标识
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function changeStatusCity($method = null){
		$id = array_unique((array)I('id',0));
		$id = is_array($id) ? implode(',',$id) : $id;
		if(empty($id)) {
			$this->error('请选择要操作的数据!');
		}
		$map[D('Admin/City')->getPk()] = array('in',$id);
		switch (strtolower($method) ){
			case 'forbid':
				$this->forbid('City', $map );
				break;
			case 'resume':
				$this->resume('City', $map );
				break;
			case 'delete':
				$obj_ward = D('Admin/Ward');
				if(!$obj_ward->judgeCity($id)){
					$this->error($obj_ward->getError());
				}else{
					S('base_city_list',null);//新增或编辑城市时清除缓存
					action_log('changeStatusCity', 'city', $id, UID);
					$this->delete('City', $map );
				}
				break;
			default:
				$this->error('参数非法');
		}
	}

	/**
	 * @todo 行政区状态修改
	 * @param string $method 标识
	 * @author Cruise <jiangyu@hrbjjhh.com>
	 */
	public function changeStatusWard($method = null){
		$id = array_unique((array)I('id',0));
		$id = is_array($id) ? implode(',',$id) : $id;
		if(empty($id)) {
			$this->error('请选择要操作的数据!');
		}
		$map[D('Admin/Ward')->getPk()] = array('in',$id);
		switch (strtolower($method) ){
			case 'forbid':
				$this->forbid('Ward', $map );
				break;
			case 'resume':
				$this->resume('Ward', $map );
				break;
			case 'delete':
				S('base_ward_list',null);//新增或编辑行政区时清除缓存
				action_log('changeStatusWard', 'ward', $id, UID);
				$this->delete('Ward', $map );
				break;
			default:
				$this->error('参数非法');
		}
	}

}
